package cn.mxb.logic.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.mxb.floor.dao.impl.BaseDaoImpl;
import cn.mxb.floor.pagination.Result;
import cn.mxb.logic.entity.SysZu;

@Repository("sysZuDAO")
public class SysZuDAO  extends BaseDaoImpl<SysZu>   {

	/**
	 * 分页
	 * @return_type: Result<SysZu>
	 */
	@SuppressWarnings("unchecked")
	public Result<SysZu> find(SysZu sysZu, int page, int size){
		String queryString = "from SysZu where 1=1";
		int start=(page-1)*size;
		int limit =size;
		String msg = "";
		return (Result<SysZu>)super.find(queryString, null, null, start, limit,msg);
	}
	
	/**
	 * 根据字段property的值value查询
	 */
	@SuppressWarnings("unchecked")
	public List<SysZu> findListByProperty(String property,String value){
		List<SysZu> list = null;
		String queryString = "from SysZu where "+property+" like '%"+value+"%' ";
		
		try{
		   list = this.getHibernateTemplate().find(queryString);
		}catch(Exception e){
			System.out.println(e);
		}
		return list;
	}
	/**
	 * 修改table，根据property的value修改field为fieldvalue
	 */
	public void updatetablebyproperty(String table,String field,String property,String value,String fieldvalue) {
        System.out.println("update"+table);
	     String hql = " update "+table+" set "+field+" = "+fieldvalue+" where "+property+" = "+value+"  ";
	     Object values[] = {table,field,property,value};
		 update(hql, values);
		 System.out.println("update");
	}
	/**
	 * 
	 * 根据字段值查询(实体)
	 */
	@SuppressWarnings("unchecked")
	public SysZu findByProperty(String property, String value) {
		List<SysZu> list = null;
		SysZu sysZu = null;
		String queryString = "from SysZu where "+property+" like '%"+value+"%' ";
		try{
		   list = this.getHibernateTemplate().find(queryString);
		   if(list.size()>0 && list !=null){
			   sysZu = list.get(0);
		   }else{
			   System.out.println("SysZu kong");
		   }
		}catch(Exception e){
			System.out.println(e);
		}
		return sysZu;
	}
	
}
